@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>举报管理</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="tabs-container">
                            <ul class="nav nav-tabs" id="navState">
                                <li data-id=""><a data-toggle="tab" aria-expanded="true">全部</a>
                                </li>
                                <li class="" data-id="0"><a data-toggle="tab" aria-expanded="true">未处理</a>
                                </li>
                                <li class="" data-id="1"><a data-toggle="tab" aria-expanded="true">已处理</a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div id="tab-1" class="tab-pane active">
                                    <div class="panel-body">
                                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                                            <thead>
                                                <tr>
                                                    <th width="220">举报商品</th>
                                                    <th class="center"  width="140">举报类型</th>
                                                    <th width="140">举报人</th>
                                                    <th width="140">被举报店铺</th>
                                                    <th width="120">举报时间</th>
                                                    <th class="center" width="70">举报状态</th>
                                                    <th>举报内容</th>
                                                    <th class="center" width="70">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            @if(!empty($list))
                                                @foreach($list as $value)
                                                <tr>
                                                    <td  title="{{array_get($value,'product_name')}}">{{substr(array_get($value,'product_name'),0,32)}}</td>
                                                    <td class="center">{{array_get($value,'report_type')}}</td>
                                                    <td>{{array_get($value,'user_name')}}</td>
                                                    <td  title="{{array_get($value,'shop_name')}}">{{substr(array_get($value,'shop_name'),0,32)}}</td>
                                                    <td>{{array_get($value,'created_at')}}</td>
                                                    <td class="center">{{array_get($value,'status_name')}}</td>
                                                    <td title="{{array_get($value,'explain')}}">{{substr(array_get($value,'explain'),0,64)}}</td>
                                                    <td class="center">
                                                        @if($value['status']== 0 )
                                                        <div class="btn-group">
                                                            <button data-toggle="dropdown" class="btn btn-primary btn-sm dropdown-toggle">操作 <span class="caret"></span>
                                                            </button>
                                                            <ul class="dropdown-menu">
                                                                <li data-id="{{array_get($value,'id')}}" data-type="2">
                                                                    <a>设为无效</a>
                                                                </li>
                                                                <li data-id="{{array_get($value,'id')}}" data-type="1">
                                                                    <a>设为已处理</a>
                                                                </li>
                                                            </ul>
                                                        </div>
                                                        @endif
                                                    </td>
                                                </tr>
                                                @endforeach
                                            @else
                                                <tr class="no-records-found center"><td colspan="8">没有找到匹配的记录</td></tr>
                                            @endif
                                            </tbody>
                                        </table>
                                        <div class="row">
                                            @include('Admin.common.paginate', ['page' => $page])
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>
    <script>
        $(document).ready(function () {
            $.getUrlParam = function(name)
            {
             var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
             var r = window.location.search.substr(1).match(reg);
             if (r!=null) return unescape(r[2]); return null;
            }
            var status=$.getUrlParam('status');
            if(status == '' || !status){
                $('#navState li').eq(0).addClass('active');
            }else if(status == 0){
                $('#navState li').eq(1).addClass('active');
            }else if(status == 1){
                $('#navState li').eq(2).addClass('active');
            }

            $("#navState li").on('click', function (event) {
                event.preventDefault();
                $("#navState li").removeClass('active');
                $(this).addClass('active');
                var state = $(this).attr('data-id');
                location.href = 'report?status=' + state;
            });

            $('.dropdown-menu li').click(function(){
                var id = $(this).attr('data-id');
                var type = $(this).attr('data-type');
                if(type==1){
                    msg = '已处理';
                }else {
                    msg = '无效';
                }
                layer.confirm('确认处理此举报信息为【'+msg+'】状态？',{
                    btn: ['确认', '取消'] //可以无限个按钮
                },function(index) {
                    $.ajax({
                        url: '',
                        type: 'PUT',
                        dataType: 'json',
                        data: {'id': id, 'state': type},
                        success: function (data) {
                            if (0 == data.code) {
                                layer.alert('设置成功！', {
                                    icon: 1
                                }, function () {
                                    location.reload();
                                });
                            } else {
                                layer.alert(data.message, {
                                    icon: 2
                                });
                            }
                        }
                    });
                    layer.close(index);
                })
            })
        });
    </script>
@endsection
